package com.cxyd.modules.job.task.logicTask;

import com.cxyd.modules.wms.dto.PostSapDTO;
import com.cxyd.modules.wms.service.PostSapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Component("post-sap")
@Slf4j
public class PostSapTask {
    private final PostSapService postSapService;
    //创建锁，防止并发情况出现
    private Lock lock = new ReentrantLock();

    public PostSapTask(PostSapService postSapService) {
        this.postSapService = postSapService;
    }

    public void scanPost() {
        lock.lock();
        try {
            //扫码是否有收货确认的数据
            List<PostSapDTO> records = postSapService.getRecords();
            if (records.isEmpty()) {
                log.info("无收货确认的数据!");
                return;
            }
        } catch (Exception e) {
            log.error("上报SAP收货确认异常，causeBy:{}", e.getMessage());
        } finally {
            lock.unlock();//释放锁
        }
    }
}
